<!DOCTYPE html>
<html lang="zh-CN">
  <head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width,initial-scale=1">
    <title>API | MyUI 4.x</title>
    <meta name="generator" content="VuePress 1.8.2">
    <link rel="icon" href="/my/favicon.ico">
    <script>
      var _hmt = _hmt || [];
      (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?c4e5f73318b5cb0c389e3d9a05f831cc";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();
    </script>
    <meta name="description" content="MyUI是美亚柏科旗下新德汇出品的Web前端一站式项目工程框架，专注于公检法行业中台系统快速搭建，框架已在多个项目实战检验。">
    <meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Expires" content="0">
    
    <link rel="preload" href="/my/assets/css/0.styles.9b3057af.css" as="style"><link rel="preload" href="/my/assets/js/app.91fb0046.js" as="script"><link rel="preload" href="/my/assets/js/597.873319f7.js" as="script"><link rel="preload" href="/my/assets/js/1781.0d914dd9.js" as="script"><link rel="preload" href="/my/assets/js/1291.730865ea.js" as="script">
    <link rel="stylesheet" href="/my/assets/css/0.styles.9b3057af.css">
  </head>
  <body>
    <div id="app" data-server-rendered="true"><div class="theme-container"><header class="navbar"><div class="sidebar-button"><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" role="img" viewBox="0 0 448 512" class="icon"><path fill="currentColor" d="M436 124H12c-6.627 0-12-5.373-12-12V80c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12zm0 160H12c-6.627 0-12-5.373-12-12v-32c0-6.627 5.373-12 12-12h424c6.627 0 12 5.373 12 12v32c0 6.627-5.373 12-12 12z"></path></svg></div> <a href="/my/" class="home-link router-link-active"><img src="/my/img/logo.png" alt="MyUI 4.x" class="logo"> <span class="site-name can-hide">MyUI 4.x</span></a> <div class="links"><div class="search-box"><input aria-label="Search" autocomplete="off" spellcheck="false" value=""> <!----></div> <nav class="nav-links can-hide"><div class="nav-item"><a href="/my/guide/" class="nav-link">
  指南
</a></div><div class="nav-item"><a href="/my/ui/components/" class="nav-link">
  组件
</a></div><div class="nav-item"><a href="/my/ui/charts/" class="nav-link">
  图表
</a></div><div class="nav-item"><a href="/my/ui/map/" class="nav-link">
  地图
</a></div><div class="nav-item"><a href="/my/ui/go/" class="nav-link router-link-active">
  关系图
</a></div><div class="nav-item"><a href="/my/ui/icon/" class="nav-link">
  图标
</a></div><div class="nav-item"><a href="/my/ui/dv/" class="nav-link">
  大屏
</a></div><div class="nav-item"><a href="/my/ui/pages/" class="nav-link">
  页面
</a></div><div class="nav-item"><a href="/my/ui/widgets/" class="nav-link">
  补丁
</a></div><div class="nav-item"><a href="http://newgateway.gitee.io/my-web/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  演示
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="JSDoc" class="dropdown-title"><span class="title">JSDoc</span> <span class="arrow down"></span></button> <button type="button" aria-label="JSDoc" class="mobile-dropdown-title"><span class="title">JSDoc</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/my/api/components.html" class="nav-link">
  基础组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/utils.html" class="nav-link">
  工具函数
</a></li><li class="dropdown-item"><!----> <a href="/my/api/charts.html" class="nav-link">
  图表组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/map.html" class="nav-link">
  地图组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/dv.html" class="nav-link">
  可视化大屏
</a></li></ul></div></div> <!----></nav></div></header> <div class="sidebar-mask"></div> <aside class="sidebar"><nav class="nav-links"><div class="nav-item"><a href="/my/guide/" class="nav-link">
  指南
</a></div><div class="nav-item"><a href="/my/ui/components/" class="nav-link">
  组件
</a></div><div class="nav-item"><a href="/my/ui/charts/" class="nav-link">
  图表
</a></div><div class="nav-item"><a href="/my/ui/map/" class="nav-link">
  地图
</a></div><div class="nav-item"><a href="/my/ui/go/" class="nav-link router-link-active">
  关系图
</a></div><div class="nav-item"><a href="/my/ui/icon/" class="nav-link">
  图标
</a></div><div class="nav-item"><a href="/my/ui/dv/" class="nav-link">
  大屏
</a></div><div class="nav-item"><a href="/my/ui/pages/" class="nav-link">
  页面
</a></div><div class="nav-item"><a href="/my/ui/widgets/" class="nav-link">
  补丁
</a></div><div class="nav-item"><a href="http://newgateway.gitee.io/my-web/" target="_blank" rel="noopener noreferrer" class="nav-link external">
  演示
  <span><svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" focusable="false" x="0px" y="0px" viewBox="0 0 100 100" width="15" height="15" class="icon outbound"><path fill="currentColor" d="M18.8,85.1h56l0,0c2.2,0,4-1.8,4-4v-32h-8v28h-48v-48h28v-8h-32l0,0c-2.2,0-4,1.8-4,4v56C14.8,83.3,16.6,85.1,18.8,85.1z"></path> <polygon fill="currentColor" points="45.7,48.7 51.3,54.3 77.2,28.5 77.2,37.2 85.2,37.2 85.2,14.9 62.8,14.9 62.8,22.9 71.5,22.9"></polygon></svg> <span class="sr-only">(opens new window)</span></span></a></div><div class="nav-item"><div class="dropdown-wrapper"><button type="button" aria-label="JSDoc" class="dropdown-title"><span class="title">JSDoc</span> <span class="arrow down"></span></button> <button type="button" aria-label="JSDoc" class="mobile-dropdown-title"><span class="title">JSDoc</span> <span class="arrow right"></span></button> <ul class="nav-dropdown" style="display:none;"><li class="dropdown-item"><!----> <a href="/my/api/components.html" class="nav-link">
  基础组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/utils.html" class="nav-link">
  工具函数
</a></li><li class="dropdown-item"><!----> <a href="/my/api/charts.html" class="nav-link">
  图表组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/map.html" class="nav-link">
  地图组件
</a></li><li class="dropdown-item"><!----> <a href="/my/api/dv.html" class="nav-link">
  可视化大屏
</a></li></ul></div></div> <!----></nav>  <ul class="sidebar-links"><li><a href="/my/ui/go/" aria-current="page" class="sidebar-link">快速上手</a></li><li><a href="/my/ui/go/diagram.html" class="sidebar-link">图形组件</a></li><li><a href="/my/ui/go/nodes.html" class="sidebar-link">内置节点模板</a></li><li><a href="/my/ui/go/links.html" class="sidebar-link">内置连线模板</a></li><li><a href="/my/ui/go/group.html" class="sidebar-link">内置分组模板</a></li><li><a href="/my/ui/go/layout.html" class="sidebar-link">布局设置</a></li><li><a href="/my/ui/go/overview.html" class="sidebar-link">缩略图组件</a></li><li><a href="/my/ui/go/palette.html" class="sidebar-link">Palette组件</a></li><li><a href="/my/ui/go/app.html" class="sidebar-link">综合应用</a></li><li><a href="/my/ui/go/api.html" aria-current="page" class="active sidebar-link">API</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/my/ui/go/api.html#creator" class="sidebar-link">creator</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/my/ui/go/api.html#creator-参数" class="sidebar-link">creator 参数：</a></li><li class="sidebar-sub-header"><a href="/my/ui/go/api.html#使用creator函数-与-gojs原版的对比" class="sidebar-link">使用creator函数 与 gojs原版的对比</a></li><li class="sidebar-sub-header"><a href="/my/ui/go/api.html#creator-的-专属配置" class="sidebar-link">creator 的 专属配置：</a></li></ul></li><li class="sidebar-sub-header"><a href="/my/ui/go/api.html#nodetemplate-基础节点模板" class="sidebar-link">nodeTemplate 基础节点模板</a><ul class="sidebar-sub-headers"><li class="sidebar-sub-header"><a href="/my/ui/go/api.html#options-的配置" class="sidebar-link">options 的配置</a></li><li class="sidebar-sub-header"><a href="/my/ui/go/api.html#theme-主题" class="sidebar-link">theme 主题</a></li></ul></li></ul></li></ul> </aside> <main class="page"> <div class="theme-default-content content__default"><h1 id="api"><a href="#api" class="header-anchor">#</a> API</h1> <h2 id="creator"><a href="#creator" class="header-anchor">#</a> creator</h2> <p>creator 函数 可以用于 生成各种 gojs 实例。</p> <h3 id="creator-参数"><a href="#creator-参数" class="header-anchor">#</a> creator 参数：</h3> <div class="language- line-numbers-mode"><pre class="language-text"><code>creator({
  name: goType, // gojs 实例类型 (如 go.Part / go.TextBlock 等)
  props: {}, // gojs 实例的配置项
  children: [] // gojs 实例的子实例
})
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br></div></div><h3 id="使用creator函数-与-gojs原版的对比"><a href="#使用creator函数-与-gojs原版的对比" class="header-anchor">#</a> 使用creator函数 与 gojs原版的对比</h3> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token comment">// gojs 官方写法：</span>
<span class="token function">$</span><span class="token punctuation">(</span>go<span class="token punctuation">.</span>Node<span class="token punctuation">,</span> go<span class="token punctuation">.</span>Panel<span class="token punctuation">.</span>Position<span class="token punctuation">,</span>
  <span class="token punctuation">{</span> background<span class="token operator">:</span> <span class="token string">'lightgray'</span> <span class="token punctuation">}</span><span class="token punctuation">,</span>
  <span class="token function">$</span><span class="token punctuation">(</span>go<span class="token punctuation">.</span>TextBlock<span class="token punctuation">,</span> <span class="token string">'node1'</span><span class="token punctuation">,</span> <span class="token punctuation">{</span> background<span class="token operator">:</span> <span class="token string">'lightgreen'</span> <span class="token punctuation">}</span><span class="token punctuation">)</span>
<span class="token punctuation">)</span>

<span class="token comment">// 使用creator</span>
<span class="token function">creator</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  name<span class="token operator">:</span> go<span class="token punctuation">.</span>Node<span class="token punctuation">,</span>
  props<span class="token operator">:</span> <span class="token punctuation">{</span>
    type<span class="token operator">:</span> go<span class="token punctuation">.</span>Panel<span class="token punctuation">.</span>Position<span class="token punctuation">,</span> 
    background<span class="token operator">:</span> <span class="token string">'lightgray'</span>
  <span class="token punctuation">}</span><span class="token punctuation">,</span>
  children<span class="token operator">:</span> <span class="token punctuation">[</span>
    <span class="token function">creator</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
      name<span class="token operator">:</span> go<span class="token punctuation">.</span>TextBlock<span class="token punctuation">,</span>
      props<span class="token operator">:</span> <span class="token punctuation">{</span>
        text<span class="token operator">:</span> <span class="token string">'node2'</span><span class="token punctuation">,</span>
        background<span class="token operator">:</span> <span class="token string">'lightgreen'</span>
      <span class="token punctuation">}</span>
    <span class="token punctuation">}</span><span class="token punctuation">)</span>
  <span class="token punctuation">]</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>  

</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br></div></div><p>虽然 使用creator 函数 生成节点时 代码比官方写法复杂，但是 creator 结构更清晰，在构建比较复杂结构的节点模板时，creator 函数更有优势。</p> <!----><h3 id="creator-的-专属配置"><a href="#creator-的-专属配置" class="header-anchor">#</a> creator 的 专属配置：</h3> <p>在 creator() 函数中 的 “props”配置中，预设了以下几个专属的配置项，</p> <ul><li>$bindings：数据绑定</li> <li>$events： 绑定事件</li> <li>$gray： 绑定置灰状态（在预设节点模板中使用，绑定主题中的置灰效果）</li> <li>$selected：绑定选中状态（在预设节点模板中使用，绑定主题中的选中效果）</li> <li>$disabled：绑定禁用状态（在预设节点模板中使用，绑定主题中的禁用效果）</li> <li>$hover：绑定鼠标经过状态（在预设节点模板中使用，绑定主题中的鼠标经过效果）</li></ul> <blockquote><p>上述所提到的主题 来自于 import {normal} from '$ui/go/template/theme'</p></blockquote> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">import</span> <span class="token punctuation">{</span>theme<span class="token punctuation">}</span> <span class="token keyword">from</span> <span class="token string">'$ui/go/template/theme'</span>
<span class="token function">creator</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
  name<span class="token operator">:</span> go<span class="token punctuation">.</span>Node<span class="token punctuation">,</span>
  props<span class="token operator">:</span> <span class="token punctuation">{</span>
    <span class="token operator">...</span><span class="token operator">...</span><span class="token punctuation">,</span>
    $gray<span class="token operator">:</span> <span class="token punctuation">{</span> 
      opacity<span class="token operator">:</span> theme<span class="token punctuation">.</span>grayOpacity
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    $hover<span class="token operator">:</span> <span class="token punctuation">{</span>
      opacity<span class="token operator">:</span> theme<span class="token punctuation">.</span>hoverOpacity
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    $disabled<span class="token operator">:</span> <span class="token punctuation">{</span>
      opacity<span class="token operator">:</span> theme<span class="token punctuation">.</span>disabledOpacity
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    $selected<span class="token operator">:</span> <span class="token punctuation">{</span>
      opacity<span class="token operator">:</span> theme<span class="token punctuation">.</span>selectedOpacity
    <span class="token punctuation">}</span><span class="token punctuation">,</span>
    $events<span class="token punctuation">,</span>
    $bindings
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br></div></div><h2 id="nodetemplate-基础节点模板"><a href="#nodetemplate-基础节点模板" class="header-anchor">#</a> nodeTemplate 基础节点模板</h2> <p>mygo 关系图中的节点模板 基础构造函数, 继承于creator，参数为 “options”(配置) 和 “theme”(主题)</p> <h3 id="options-的配置"><a href="#options-的配置" class="header-anchor">#</a> options 的配置</h3> <table><thead><tr><th>配置名</th> <th>说明</th> <th>类型</th></tr></thead> <tbody><tr><td>props</td> <td>节点（$(go.Node, {...})）的全局配置，可以覆盖其他配置</td> <td>object</td></tr> <tr><td>wrapper</td> <td>Node节点下面第一个（展示为容器）子元素的配置， 用于配置背景边框等</td> <td>object</td></tr> <tr><td>tooltip</td> <td>配置是否显示提示语</td> <td>object</td></tr> <tr><td>lock</td> <td>配置是否</td> <td>object/boolean</td></tr> <tr><td>tags</td> <td>配置是否显示标签</td> <td>object/array</td></tr> <tr><td>badge</td> <td>配置是否显示数字提示</td> <td>object</td></tr> <tr><td>children</td> <td>给节点添加子元素</td> <td>array</td></tr> <tr><td>$events</td> <td>给节点绑定事件</td> <td>object</td></tr> <tr><td>$bindings</td> <td>给节点绑定数据</td> <td>array/object</td></tr></tbody></table> <h3 id="theme-主题"><a href="#theme-主题" class="header-anchor">#</a> theme 主题</h3> <div class="language-javascript line-numbers-mode"><pre class="language-javascript"><code><span class="token keyword">const</span> normal <span class="token operator">=</span> <span class="token punctuation">{</span>
  <span class="token comment">// 背景颜色</span>
  fill<span class="token operator">:</span> <span class="token string">'rgba(124,129,143,0.3)'</span><span class="token punctuation">,</span>
  <span class="token comment">// 边框样式</span>
  stroke<span class="token operator">:</span> <span class="token string">'#7c818f'</span><span class="token punctuation">,</span>
  <span class="token comment">// 文本/icon颜色</span>
  color<span class="token operator">:</span> <span class="token string">'#7c818f'</span><span class="token punctuation">,</span>
  <span class="token comment">// 形状外的文本颜色</span>
  textColor<span class="token operator">:</span> <span class="token string">'#ffffff'</span><span class="token punctuation">,</span>
  strokeWidth<span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span>
  opacity<span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
  hoverOpacity<span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
  grayOpacity<span class="token operator">:</span> <span class="token number">0.25</span><span class="token punctuation">,</span>
  selectedOpacity<span class="token operator">:</span> <span class="token number">1</span><span class="token punctuation">,</span>
  <span class="token comment">// 边框厚度</span>
  disabledOpacity<span class="token operator">:</span> <span class="token number">0.1</span><span class="token punctuation">,</span>
  <span class="token comment">// 默认图标</span>
  geometryString<span class="token operator">:</span> defaultIcon<span class="token punctuation">,</span>
  <span class="token comment">// 默认图片</span>
  imageSource<span class="token operator">:</span> defaultImage<span class="token punctuation">,</span>
  <span class="token comment">// 标签颜色</span>
  tags<span class="token operator">:</span> <span class="token punctuation">[</span><span class="token string">'#0099cc'</span><span class="token punctuation">,</span> <span class="token string">'#ffb609'</span><span class="token punctuation">,</span> <span class="token string">'#ef5350'</span><span class="token punctuation">,</span> <span class="token string">'#00d156'</span><span class="token punctuation">,</span> <span class="token string">'#f431ba'</span><span class="token punctuation">]</span><span class="token punctuation">,</span>

  selectedFill<span class="token operator">:</span> <span class="token string">'rgba(64,158,255,0.1)'</span><span class="token punctuation">,</span>
  selectedStrokeWidth<span class="token operator">:</span> <span class="token number">2</span><span class="token punctuation">,</span>
  selectedStroke<span class="token operator">:</span> <span class="token string">'#409eff'</span>
<span class="token punctuation">}</span>
</code></pre> <div class="line-numbers-wrapper"><span class="line-number">1</span><br><span class="line-number">2</span><br><span class="line-number">3</span><br><span class="line-number">4</span><br><span class="line-number">5</span><br><span class="line-number">6</span><br><span class="line-number">7</span><br><span class="line-number">8</span><br><span class="line-number">9</span><br><span class="line-number">10</span><br><span class="line-number">11</span><br><span class="line-number">12</span><br><span class="line-number">13</span><br><span class="line-number">14</span><br><span class="line-number">15</span><br><span class="line-number">16</span><br><span class="line-number">17</span><br><span class="line-number">18</span><br><span class="line-number">19</span><br><span class="line-number">20</span><br><span class="line-number">21</span><br><span class="line-number">22</span><br><span class="line-number">23</span><br><span class="line-number">24</span><br><span class="line-number">25</span><br><span class="line-number">26</span><br><span class="line-number">27</span><br></div></div></div> <footer class="page-edit"><!----> <!----></footer> <div class="page-nav"><p class="inner"><span class="prev">
      ←
      <a href="/my/ui/go/app.html" class="prev">
        综合应用
      </a></span> <!----></p></div> </main></div><div class="global-ui"></div></div>
    <script src="/my/assets/js/app.91fb0046.js" defer></script><script src="/my/assets/js/597.873319f7.js" defer></script><script src="/my/assets/js/1781.0d914dd9.js" defer></script><script src="/my/assets/js/1291.730865ea.js" defer></script>
  </body>
</html>
